package com.jyw.seed.controller;


import com.jyw.seed.config.Resource;
import com.jyw.seed.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/th")
public class IndexController {


	private final Resource resource;

	@Autowired
	public IndexController(Resource resource) {
		this.resource = resource;
	}

	@RequestMapping("/index")
	public String index(ModelMap map){
		map.addAttribute("name",resource.getWebsite());
		return "index";
	}

	@RequestMapping("/form")
	public String from(ModelMap map){
		map.addAttribute("user",new User("jyw"));
		return "post";
	}

	@RequestMapping("/post")
	public String post(User user){
		System.out.println(user.getUsername());
		return "redirect:index";
	}

	@RequestMapping("/err/ajax/page")
	public String ajaxErrorPage(){
		return "ajax-error";
	}

}
